unit dbbase;

interface

uses
  Forms, RzRadChk, StdCtrls, Mask, RzEdit, RzButton, Grids, DBGrids, RzDBGrid,
  Classes, Controls, ExtCtrls, Graphics, SysUtils, Windows, DB, ADODB,
  Buttons, Messages;

type
  TdbbaseFrm = class(TForm)
    bg: TPanel;
    DataBG: TPanel;
    dbgrid: TRzDBGrid;
    pal_picbg: TPanel;
    GroupBox: TGroupBox;
    btn_find: TRzBitBtn;
    btn_export: TRzBitBtn;
    btn_print: TRzBitBtn;
    btn_add: TRzBitBtn;
    btn_edit: TRzBitBtn;
    btn_del: TRzBitBtn;
    btn_exit: TRzBitBtn;
    ckbox_shwpic: TRzCheckBox;
    edit_qsearch: TRzEdit;
    btn_qsearch: TRzBitBtn;
    pal_ctrl: TPanel;
    btnClose: TSpeedButton;
    labCaption: TLabel;
    DataSource: TDataSource;
    procedure ckbox_shwpicClick(Sender: TObject);
    procedure btn_exitClick(Sender: TObject);
    procedure btn_findClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btn_printClick(Sender: TObject);
    procedure edit_qsearchMouseEnter(Sender: TObject);
    procedure edit_qsearchMouseLeave(Sender: TObject);
    procedure btn_delClick(Sender: TObject);
    procedure btn_addClick(Sender: TObject);
    procedure btn_editClick(Sender: TObject);
    procedure dbgridDblClick(Sender: TObject);
    procedure btn_exportClick(Sender: TObject);
    procedure btn_qsearchClick(Sender: TObject);
    procedure edit_qsearchKeyPress(Sender: TObject; var Key: Char);
    procedure dbgridTitleClick(Column: TColumn);
    procedure btnCloseClick(Sender: TObject);
    procedure pal_ctrlResize(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure dbgridKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
    OldGridWnd : TWndMethod;
    procedure NewGridWnd (var Message:TMessage);
  public
    { Public declarations }
    Procedure IniParam;virtual;abstract;
    procedure QFindRcd;virtual;abstract;
    procedure PrintRpt;virtual;abstract;
    procedure FindRcd;virtual;abstract;
    procedure AddRcd;virtual;abstract;
    procedure EditRcd;virtual;abstract;
    procedure DelRcd;virtual;abstract;
    procedure CutCnnt;virtual;abstract;
    procedure FrmExit;virtual;abstract;
  end;

var
  dbbaseFrm: TdbbaseFrm;

implementation

{$R *.dfm}

uses IncludeFile, dbgrid2excel;

procedure TdbbaseFrm.NewGridWnd(var Message: TMessage);
//var
//  IsNeg : Boolean;
begin
  if Message.Msg = WM_MOUSEWHEEL then begin
    ;
  end else
    OldGridWnd(Message);
end;

procedure TdbbaseFrm.ckbox_shwpicClick(Sender: TObject);
begin
  if ckbox_shwpic.Checked then begin
    pal_picbg.Show;
  end else
    pal_picbg.Hide;
end;

procedure TdbbaseFrm.btn_exitClick(Sender: TObject);
begin
  FrmExit;
end;

procedure TdbbaseFrm.btn_findClick(Sender: TObject);
begin
  FindRcd;
end;

procedure TdbbaseFrm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action:=CaFree;
end;

procedure TdbbaseFrm.btn_printClick(Sender: TObject);
begin
  PrintRpt;
end;

procedure TdbbaseFrm.edit_qsearchMouseEnter(Sender: TObject);
begin
  with edit_qsearch do begin
    Font.Size:=8;
    Color:=clWindow;
    FrameVisible:=False;
    btn_qsearch.Show;
  end;
end;

procedure TdbbaseFrm.edit_qsearchMouseLeave(Sender: TObject);
begin
  with edit_QSearch do begin
    if Text='' then begin
      Font.Size:=8;
      Color:=clinfoBk;
      FrameVisible:=True;
      btn_QSearch.Hide;
    end;
  end;
end;

procedure TdbbaseFrm.btn_delClick(Sender: TObject);
begin
  DelRcd;
end;

procedure TdbbaseFrm.btn_addClick(Sender: TObject);
begin
  AddRcd;
end;

procedure TdbbaseFrm.btn_editClick(Sender: TObject);
begin
  EditRcd;
end;

procedure TdbbaseFrm.dbgridDblClick(Sender: TObject);
begin
  EditRcd;
end;

procedure TdbbaseFrm.btn_exportClick(Sender: TObject);
begin
  DBGridToExcel([DBGrid]);
end;

procedure TdbbaseFrm.btn_qsearchClick(Sender: TObject);
begin
  QFindRcd;
end;

procedure TdbbaseFrm.edit_qsearchKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then  begin
    if edit_QSearch.Text <>'' then
      QFindRcd
    else begin
      with DBGrid.DataSource.DataSet do begin
        Active:=False;
        Filter:='';
        Filtered:=True;
        Active:=True;
      end;
    end;
  end;
end;

procedure TdbbaseFrm.dbgridTitleClick(Column: TColumn);
begin
  if TADOQuery(DBGrid.DataSource.DataSet).Sort=Column.FieldName+' ASC' then
    TADOQuery(DBGrid.DataSource.DataSet).Sort:=Column.FieldName+' DESC'
  else
    TADOQuery(DBGrid.DataSource.DataSet).Sort:=Column.FieldName+' ASC';
end;

procedure TdbbaseFrm.btnCloseClick(Sender: TObject);
begin
  FrmExit;
end;

procedure TdbbaseFrm.pal_ctrlResize(Sender: TObject);
begin
  btnClose.Left:=pal_ctrl.Width-btnClose.Width-3;
end;

procedure TdbbaseFrm.FormCreate(Sender: TObject);
var
  I:integer;
begin
  OldGridWnd := DBGrid.WindowProc;
  DBGrid.WindowProc := NewGridWnd;
  for I:=0 to ComponentCount-1 do begin
    if Components[I] is TLabel then begin
      if 0<>TLabel(Components[I]).Tag then
        TLabel(Components[I]).Caption:=
                GetCaption(name,TLabel(Components[I]).Tag);
    end;
    if Components[I] is TRzBitBtn then begin
      if 0<>TRzBitBtn(Components[I]).Tag then
        TRzBitBtn(Components[I]).Caption:=
                GetCaption(name,TRzBitBtn(Components[I]).Tag);
    end;
    if Components[I] is TRzCheckBox then begin
      if 0<>TRzCheckBox(Components[I]).Tag then
        TRzCheckBox(Components[I]).Caption:=
                GetCaption(name,TRzCheckBox(Components[I]).Tag);
    end;

  end;
end;

procedure TdbbaseFrm.dbgridKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  case Key of
    vk_up:dbgrid.DataSource.DataSet.MoveBy(-30);
    vk_down:dbgrid.DataSource.DataSet.MoveBy(30);
    vk_home:dbgrid.DataSource.DataSet.First;
    vk_end:dbgrid.DataSource.DataSet.Last;
  end;
end;

end.


